package com.example.module_service.vm

import com.example.lib_common.view.vm.BaseViewModel
import com.example.module_service.api.ServiceApiService
import com.example.module_service.entity.CarAddEntity
import com.example.module_service.entity.CarAddParam
import com.example.module_service.model.ServiceRepository
import com.example.module_service.model.ServiceResultData
import dagger.hilt.android.lifecycle.HiltViewModel
import kotlinx.coroutines.launch
import javax.inject.Inject

@HiltViewModel
class CarViewModel @Inject constructor(private val apiService: ServiceApiService):
    BaseViewModel<ServiceRepository, ServiceResultData<List<CarAddEntity>>>(){
    fun getAddCar(carAddParam: CarAddParam){
        mViewModelScope.launch (mDispatcher){
            try {
                val result=apiService.getAddCar(carAddParam)
                val res=ServiceResultData(
                    code = result.code,
                    message=result.message,
                    data = listOf(result.data)
                )
                mSuccessLiveData.postValue(res)
            }catch (e:Exception){
                mErrorLiveData.postValue("请求失败:${e.message}")
            }
        }
    }
}